package init;

import gui.AppMainFrame;
import gui.BuildingSketchView;
import gui.CViewPanel;
import gui.ConcreteView;
import gui.DetailsView;
import gui.IView;
import gui.Slider;

import java.awt.BorderLayout;
import java.util.ArrayList;

import models.Artist;
import controllers.AppCtrlr;
import data.DataParser;


/**
 * 
 * @author Chrystopher
 * Instantiate and run the main application here.
 */
public class AppLauncher {
	
	static public BuildingSketchView bsv;
	static private ConcreteView view1;
	static public int filterValue1=1960;
	static public int filterValue2=2000;
	public static ArrayList<Integer>selectedIndex= new ArrayList<Integer>(), buildings = new ArrayList<Integer>();
	static private IView slider;
	static private DetailsView details;

	public static void main(String[] args) {
		
		//load data
		DataParser.initData();
		
		
		//create all frame 
		AppMainFrame frame = new AppMainFrame();
		view1 = new ConcreteView(new CViewPanel(), "Major Styles & Artists");
		details= new DetailsView("Details");
		slider= new Slider("Time Slider");		
		
		
		frame.addView(view1,BorderLayout.CENTER);
		frame.addView(details,BorderLayout.WEST);
		frame.getPanel().add(slider, BorderLayout.SOUTH);//BorderLayout.SOUTH);
		frame.setVisible(true);
		
		//Wizard
		AppCtrlr ctrl = new AppCtrlr();
		if(ctrl.checkForInitWizard()){
			ctrl.popInitWizard();
		}
		
	}
	//Call to refresh the applet when the slider has changed year.
	public static void refreshApplet(int fv1,int fv2) {
		filterValue1=fv1;
		filterValue2=fv2;
		selectedIndex=new ArrayList<Integer>();
		DetailsView.textAreaArtistDetail.setText("");
		DetailsView.artistOverNameLabel.setText("");
		refreshPieChart(null);
		((BuildingSketchView) view1.embeddedApplet).popOk=false;
	}
	
	//Call to refresh the pie chart on the screen
	public static void refreshPieChart(ArrayList<Artist> artistInfluencerList ) {
		int [] v= new int[13];
		
		for(int i=0; i<13 ;i++){
			details.pc.slices[i].value=0;
		}
			if(artistInfluencerList!=null){
			for(int i=0; i<artistInfluencerList.size();i++){
				try {
					details.pc.slices[artistInfluencerList.get(i).getSubStyle().getMajorStyle().getId()].value+=(100/artistInfluencerList.size());
				} catch (Exception e) {
					// TODO: handle exception
				}
				
			}
		}

		details.pc.repaint();
	}
}
